package han.chensing.latos.common.level.sample;

import java.io.Serial;
import java.io.Serializable;
import java.util.Objects;

import han.chensing.latos.common.level.function.TimeObject;

public class Sample implements Serializable, TimeObject {

    @Serial
    private static final long serialVersionUID=11451403L;

    private String name;
    private float time;
    private int referTimes=0;

    public Sample() {
        this.name="Sample";
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public float getTime() {
        return time;
    }

    public void setTime(float absoluteTime) {
        this.time = absoluteTime;
    }

    public void addReference(){
        referTimes++;
    }

    public void decreaseReference(){
        referTimes--;
        if (referTimes<0)referTimes=0;
    }

    public boolean hasReference(){
        return referTimes!=0;
    }

    @Override
    public String toString() {
        return name+" - "+ time;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Sample sample = (Sample) o;
        return time == sample.time && Objects.equals(name, sample.name);
    }
}
